package com.lotus.lqmp.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lotus.idaas.sdk.common.BaseResult;
import com.lotus.lqmp.base.biz.bean.PageQuery;
import com.lotus.lqmp.service.biz.bean.EcuInventoryImportModel;
import com.lotus.lqmp.service.common.utils.ExcelUtils;
import com.lotus.lqmp.service.controller.vo.req.EcuInventoryAddReq;
import com.lotus.lqmp.service.controller.vo.req.EcuInventoryQueryReq;
import com.lotus.lqmp.service.controller.vo.req.EcuInventoryUpdateReq;
import com.lotus.lqmp.service.controller.vo.resp.EcuInventoryAddResp;
import com.lotus.lqmp.service.controller.vo.resp.EcuInventoryQueryResp;
import com.lotus.lqmp.service.controller.vo.resp.EcuInventoryUpdateResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lotus.lqmp.service.service.EcuInventoryService;
import org.springframework.web.multipart.MultipartFile;

import java.util.Collections;
import java.util.List;


/**
 * ECU清单表Controller
 *
 * @author Shiheng.Liu1
 * @date 2022-03-29
 */
@Slf4j
@RestController
@Api(tags = "ECU清单管理")
@RequestMapping("/api/ecuInventory")
public class EcuInventoryController{
    @Autowired
    private EcuInventoryService EcuInventoryService;

    /**
     * 新增ECU清单管理记录
     * @param ecuInventoryAddReq：ECU清单管理新增属性
     * @return：响应ECU清单管理新增结果
     */
    @ApiOperation("ECU清单管理新增")
    @PostMapping("/save")
    public BaseResult<EcuInventoryAddResp> saveEcuInventoryRecord(EcuInventoryAddReq ecuInventoryAddReq){
        String projectName = ecuInventoryAddReq.getProjectName();
        String topologicalGraphVersion = ecuInventoryAddReq.getTopologicalGraphVersion();
        MultipartFile ecuAnnex = ecuInventoryAddReq.getEcuAnnex();
        List<EcuInventoryImportModel> models = ExcelUtils.importExcel(ecuAnnex, 0, 2, EcuInventoryImportModel.class);
        //todo.excel文件导入数据校验
        return BaseResult.fail(new EcuInventoryAddResp());
    }

    /**
     * 删除ECU清单管理记录
     * @param ids: ECU清单管理被删除关联的ids
     * @return: 响应ECU清单管理删除结果
     */
    @ApiOperation("ECU清单管理删除")
    @PostMapping("/batchRemove")
    public BaseResult deleteEcuInventoryRecord(@RequestBody List<String> ids){
        //todo
        return BaseResult.ok();
    }

    /**
     * 修改保存ECU清单管理记录
     * @param ecuInventoryUpdateReq: ECU清单管理修改属性
     * @return：响应ECU清单管理修改保存结果
     */
    @ApiOperation("ECU清单管理修改保存")
    @PostMapping("/updateSave")
    public BaseResult<EcuInventoryUpdateResp> updateSaveEcuInventoryRecord(EcuInventoryUpdateReq ecuInventoryUpdateReq){
        String regionId = ecuInventoryUpdateReq.getId();
        String projectName = ecuInventoryUpdateReq.getProjectName();
        String topologicalGraphVersion = ecuInventoryUpdateReq.getTopologicalGraphVersion();
        MultipartFile ecuAnnex = ecuInventoryUpdateReq.getEcuAnnex();
        List<EcuInventoryImportModel> models = ExcelUtils.importExcel(ecuAnnex, 0, 2, EcuInventoryImportModel.class);
        //todo.excel文件导入数据校验
        return BaseResult.ok(new EcuInventoryUpdateResp());
    }

    /**
     * 查询ECU清单管理记录
     * @param queryInfo：ECU清单管理查询限制条件
     * @return: 响应ECU清单管理查询结果
     */
    @ApiOperation("ECU清单管理查询")
    @PostMapping("/findAll")
    public BaseResult<Page<EcuInventoryQueryResp>> queryEcuInventoryRecords(@RequestBody PageQuery<EcuInventoryQueryReq> queryInfo){
        //todo
        Page<EcuInventoryQueryResp> page = new Page<>(queryInfo.getPageNum(), queryInfo.getPageSize());
        page.setRecords(Collections.singletonList(new EcuInventoryQueryResp()));
        page.setTotal(1);
        return BaseResult.ok(page);
    }
}
